package com.renjiyue;

import com.renjiyue.pojo.Hello;
import com.renjiyue.pojo.User;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class test {
    @Test
    public void test3(){
        //解析beans.xml文件,生成管理对应的Bean对象
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        //getBean:参数几位Spring配置文件中的Bean的id
        Hello hello = (Hello)context.getBean("hello");
        hello.show();
    }
    @Test
    public void test4() {
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        //在执行getBean的时候，user已经创建好了，通过了无参构造
        User user = (User) context.getBean("user");
        //调用对象的方法
        user.show();
    }
    @Test
    public void test5() {
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        //在执行getBean的时候，user已经创建好了，通过了无参构造
        User user1 = (User) context.getBean("user1");
        //调用对象的方法
        user1.show();
        System.out.println("==========================");
        User user2 = (User) context.getBean("user2");
        //调用对象的方法
        user2.show();
        System.out.println("==========================");
        User user3 = (User) context.getBean("user3");
        //调用对象的方法
        user3.show();`

    }
}
